#include "PowerService.h"

void PowerService::init()
{
}

void PowerService::sleep()
{
	rtc_gpio_pullup_en(GPIO_NUM_39);
	esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, 0);
	esp_deep_sleep_start();
}

void PowerService::printWakeupReason()
{
	esp_sleep_wakeup_cause_t wakeup_reason;

	wakeup_reason = esp_sleep_get_wakeup_cause();
	
	switch (wakeup_reason)
	{
		case 1: Serial.println("Wakeup caused by external signal using RTC_IO"); break;
		case 2: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
		case 3: Serial.println("Wakeup caused by timer"); break;
		case 4: Serial.println("Wakeup caused by touchpad"); break;
		case 5: Serial.println("Wakeup caused by ULP program"); break;
		default: Serial.println("Wakeup was not caused by deep sleep"); break;
	}
}

PowerService powerService;
